﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Company.StudyClub.BLL.Site;
using Company.StudyClub.Model;
using System.Collections.Generic;

public partial class Access_RoleFunction : PageBase
{
    public int RoleID = 0;
   
    protected void Page_Load(object sender, EventArgs e)
    {
        RoleID = GetInt("id");

        if (!IsPostBack)
        {
            BindFunctionList();
        }
    }

    protected void BindFunctionList()
    {
        RoleFunctionsBLL objRFBLL = new RoleFunctionsBLL();
        string functions = objRFBLL.GetRoleFunctions(RoleID);

        StringBuilder sb = new StringBuilder();
        sb.Append("<table cellspacing=\"0\">");
        FunctionBLL objBLL = new FunctionBLL();
        List<Site_Functions> functionList = objBLL.GetFunctions();
        int currentFunctionID = 0;
        int currSectionID = 0;
        int currGroupID = 0;
        for (int i = 0; i < functionList.Count; i++)
        {
            Site_Functions model = (Site_Functions)functionList[i];
            if (model.SectionID != currSectionID)
            {
                sb.Append("<tr><th>");
                sb.Append(model.SectionName.ToString());
                sb.Append("</th></tr>");
                currSectionID = model.SectionID;
            }
            if (model.GroupID != currGroupID)
            {
                sb.Append("<tr class=\"tdmover\"><td>");
                sb.Append(model.GroupName.ToString());
                sb.Append("</td></tr>");
                currGroupID = model.GroupID;
            }
            if (model.FunctionID != currentFunctionID)
            {
                sb.Append("<tr><td>");
                sb.Append("<input type=\"checkbox\" value=\"");                
                sb.Append(model.FunctionID.ToString());
                sb.Append("\"");
                if (functions.IndexOf("/" + model.FunctionID.ToString() + "/") >= 0)
                {
                    sb.Append(" checked=\"checked\"");
                }
                sb.Append(" />&nbsp;");
                sb.Append(model.FunctionName.ToString());
                sb.Append("</td></tr>");
                currentFunctionID = model.FunctionID;
            }
        }
        sb.Append("</table>");
        this.dv_Functions.InnerHtml = sb.ToString();
    }
}
